<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="mini" label-width="80px">
      <el-row :gutter="20">
        <el-col :span="4">
          <el-form-item label="资产名称" prop="assetsName">
            <el-input v-model="queryParams.assetsName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="资产类型" prop="assetsType">
            <el-select v-model="queryParams.assetsType" placeholder="请选择" clearable @keyup.enter.native="handleQuery">
              <el-option v-for="dict in dict.type.cld_assets_type" :key="dict.value" :label="dict.label"
                :value="parseInt(dict.value)"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="资产ID" prop="assetsIdCard">
            <el-input v-model="queryParams.assetsIdCard" placeholder="请输入" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label-width="10px">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table v-loading="loading" :data="list" border>
      <el-table-column label="资产名称" align="center" prop="assetsName" />
      <el-table-column label="资产类型" align="center" prop="assetsType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_assets_type" :value="scope.row.assetsType" />
        </template>
      </el-table-column>
      <el-table-column label="资产型号" align="center" prop="assetsModel" />
      <el-table-column label="资产ID" align="center" prop="assetsIdCard" />
      <el-table-column label="累计已增值期数" align="center" prop="addedNumber" />
      <el-table-column label="累计已增值金额" align="center" prop="addedMoney">
        <template slot-scope="scope">
          {{ toMoney(scope.row.addedMoney) }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleRepairDetails(scope.row)"
            v-hasPermi="['cld:depreciation:query']">增值明细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />


    <!-- 折旧明细 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-table v-loading="loading" :data="detailsList">
        <el-table-column label="项目区域" align="center" prop="projectRegion">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.cld_project_region" :value="scope.row.projectRegion" />
          </template>
        </el-table-column>
        <el-table-column label="项目名称" align="center" prop="projectName" />
        <el-table-column label="累计已增值期数" align="center" prop="addedNumber" />
        <el-table-column label="最近投放时间" align="center">
          <template slot-scope="scope">
            {{ scope.row.year + '-' + scope.row.month + '-' + scope.row.day }}
          </template>
        </el-table-column>
        <el-table-column label="每期增值金额" align="center">
          <template slot-scope="scope">
            {{ toMoney(scope.row.money) }}
          </template>
        </el-table-column>
        <el-table-column label="涉及金额" align="center">
          <template slot-scope="scope">
            {{ toMoney(scope.row.addedMoney) }}
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { listDepreciation, getListDepreciation } from "@/api/cld/depreciation";

export default {
  name: "repair",
  dicts: ['cld_assets_type', 'cld_project_region'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      detailsTotal: 0,
      // 折旧明细
      open: false,
      title: '',
      // 资产折旧表格数据
      list: [],
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        lossType: 2,
        assetsName: null,
        assetsIdCard: null,
        assetsType: null
      },
      // 明细查询参数
      detailsQueryParams: {
        pageNum: 1,
        pageSize: 10,
        assetsIdCard: null,
        lossType: 2,
        status: 2,
        params: {
          groupType: 2
        }
      },
      // 折旧明细
      detailsList: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询资产维修列表 */
    getList() {
      this.loading = true;
      getListDepreciation(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 折旧明细 */
    handleRepairDetails(row) {
      this.detailsList = [];
      this.detailsQueryParams.assetsIdCard = row.assetsIdCard;
      listDepreciation(this.detailsQueryParams).then(response => {
        this.detailsList = response.rows;
        this.detailsTotal = response.total;
        this.title = row.assetsName + '-' + row.assetsIdCard + '-折旧明细'
        this.open = true;
      })
    },
    /** 维修成本 */
    handleRepairCost() {
    },
  }
};
</script>
<style scoped>
.el-range-editor.el-input__inner {
  width: 100%;
}

.el-select {
  width: 100%;
}
</style>
